package com.fast.cms.web.mobile;

import java.io.IOException;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.fast.base.util.LogUtils;
import com.fast.base.db.page.PageView;
import com.fast.base.util.web.ResponseData;
import com.fast.base.web.BaseController;
import com.fast.cms.model.article.Article;
import com.fast.cms.service.article.ArticleService;
import com.fast.cms.web.form.ArticleListForm;
import com.fast.cms.web.form.CheckArticleForm;
import com.fast.user.model.admin.AdminUser;

/**
 * ClassName:AppArticleController <br/>
 * 用途:手机端资讯操作类 <br/>
 * 开发人员：lushuifa http://lushuifa.iteye.com/ 
 * 邮箱:lsflu@126.com
 * @version
 * @since JDK 1.6
 * @see Date: 2016年11月30日 14时51分41秒 <br/>
 */
@Controller("AppArticleController")
@RequestMapping("/app/article")
public class AppArticleController extends BaseController{
	
	
	@Resource(name="articleService")
	private ArticleService articleService;
	
	/**
	 * 审批资讯文章
	 * @param checkArticleForm
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/checkArticle.do")
	public ResponseData checkArticle(CheckArticleForm checkArticleForm){
		ResponseData j = new ResponseData();
		boolean actionFlag = this.articleService.checkArticle(checkArticleForm);
		if(actionFlag){
			//审核机关操作 审核通过时则应该扣除库存
			j.buildSuccessResponse();
		}else{
			j.setCode("01");
			j.setMsg("操作失败,请重试或者重新登录试试！");
		}
		return j;
	}
	
	
	
	/**
	 * 分页获取列表
	 * @return PageView<Article>
	 * @throws IOException 
	 */
	@ResponseBody
	@RequestMapping(value="/getArticleList.do")
	public ResponseData getArticleList(ArticleListForm articleListForm){
		LogUtils.info("getArticleList param:"+articleListForm.toString());
		ResponseData responseData = new ResponseData();
		try {
			PageView<Article> pageView = this.articleService.getArticleList(articleListForm);
			responseData.setData(pageView);
		} catch (Exception e) {
			LogUtils.error("getArticleList err:",e);
			responseData.failue();
		}
		LogUtils.info("getArticleList result:"+responseData.toString());
 		return responseData;
	}
	
	/**
	 * 获取资讯详情
	 */
	@ResponseBody
	@RequestMapping(value="/getArticleDetail.do")
	public ResponseData getArticleDetail(String uuid){
		LogUtils.info("getArticleDetail uuid:"+uuid);
		ResponseData responseData = new ResponseData();
		try {
			Article article  = this.articleService.queryForBeanByUUID(Article.class, uuid);
			responseData.setData(article);
		} catch (Exception e) {
			LogUtils.error("getArticleDetail err:",e);
			responseData.failue();
		}
		LogUtils.info("getArticleDetail result:"+responseData.toString());
 		return responseData;
	}
}
